package conson.tech.manage.app.controller.backstage;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import conson.tech.core.constant.SecurityConstants;
import conson.tech.core.response.Response;
import conson.tech.manage.api.app.constant.AppCommon;
import conson.tech.manage.app.constant.BusinessMessage;
import conson.tech.manage.app.entity.pojo.AppConfig;
import conson.tech.manage.app.entity.pojo.AppGroupConfig;
import conson.tech.manage.app.entity.pojo.AppPageConfig;
import conson.tech.manage.app.entity.pojo.AppVersion;
import conson.tech.manage.app.entity.vo.*;
import conson.tech.manage.app.service.AppConfigService;
import conson.tech.manage.app.service.AppGroupConfigService;
import conson.tech.manage.app.service.AppPageConfigService;
import conson.tech.manage.app.service.AppVersionService;
import conson.tech.manage.common.service.CommonUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * ClassName: AppBackstageController
 * Description: 页面配置分组配置app配置控制器
 * Author: HXL
 * Date: 2020/4/23 2:11 下午
 * Version: 1.0
 */
@Slf4j
@RestController
@Api(value = "页面配置分组配置app配置控制器",tags = "页面配置分组配置app配置控制器")
@RequestMapping(SecurityConstants.MANAGERAPI_MATCHER+"/")
public class AppBackstageController {

    @Autowired
    private AppPageConfigService appPageConfigService;
    @Autowired
    private AppGroupConfigService appGroupConfigService;
    @Autowired
    private AppConfigService appConfigService;
    @Autowired
    private AppVersionService appVersionService;

    @Autowired
    private CommonUploadService commonUploadService;

    @ApiOperation(value = "图片上传" ,notes = "")
    @PostMapping("app/upload/picture")
    @ApiImplicitParam(name = "requestPageType",value = "页面请求类型:1-首页默认应用 2-应用配置（全部应用管理）3-首页模块  " +
            "4-生活页模块 5-信豆页引导模块 6-功能专题页模块",required =true,dataType = "String")
    public Response<String> userUploadPicture(@RequestParam("file") MultipartFile file, HttpServletRequest request){
        if (file == null){
            return Response.fail("上传失败");
        }
        String requestPageType = request.getParameter("requestPageType");
        String path = "/icon4";
        //页面请求类型:1-首页默认应用 2-应用配置（全部应用管理）3-首页模块  4-生活页模块 5-信豆页引导模块 6-功能专题页模块
        if (!StringUtils.isEmpty(requestPageType)){
            switch (requestPageType){
                case "2":
                    path = "/allAppIcon";
                    break;
                case "3":
                    path = "/homeIcon";
                    break;
                case "4":
                    path = "/lifeIcon";
                    break;
                case "5":
                    path = "/letterBeanIcon";
                    break;
                case "6":
                    path = "/specialIcon";
                    break;
            }
        }
        String url = commonUploadService.commonUpload(file, path);
        if(StringUtils.isEmpty(url)){
            return Response.fail("上传失败");
        }
        return Response.success(url);
    }

    //====================== 功能专题页 start =====================//
    /**
     * Title: 功能专题-分页查询
     * Description:
     * @param pageVo
     * @return: conson.tech.core.response.Response<com.baomidou.mybatisplus.extension.plugins.pagination.Page<conson.tech.manage.app.entity.vo.LetterBeanAppVo>>
     * Company: GX
     * Author HXL
     * Date 2020/4/27 3:10 下午
     */
    @ApiOperation(value = "功能专题-分页查询",notes = "功能专题-分页查询")
    @ApiImplicitParam(name = "pageVo",value = "请求入参封装",required =true,dataType = "PageVo")
    @PostMapping("special/query")
    public Response<Page<AppSpecialVo>> querySpecial(@Valid @RequestBody PageVo pageVo){
        Page<AppSpecialVo> page = appGroupConfigService.querySpecial(pageVo);
        return  Response.success(page);
    }
       /**
        * Title: 功能专题-新增
        * Description:
        * @param appSpecialVo
        * @return: conson.tech.core.response.Response
        * Company: GX
        * Author HXL
        * Date 2020/4/27 3:47 下午
        */
    @ApiOperation(value = "功能专题-新增",notes = "功能专题-新增")
    @ApiImplicitParam(name = "appSpecialVo",value = "请求入参封装",required =true,dataType = "AppSpecialVo")
    @PostMapping("special/add")
    public Response addSpecial(@Valid @RequestBody AppSpecialVo appSpecialVo){
        log.info("AppBackstageController -> addSpecial【功能专题-新增】入参【{}】", JSONUtil.toJsonStr(appSpecialVo));

        if (!CollectionUtils.isEmpty(appSpecialVo.getSpecialSubVoList())){
            for (AppSpecialSubVo appSpecialSubVo : appSpecialVo.getSpecialSubVoList()) {
                if (appSpecialSubVo.getNavType() == 1){
                        if (StringUtils.isEmpty(appSpecialSubVo.getAppId())){
                            return Response.fail(BusinessMessage.NATYPE_ERROR);
                        }
                }
                if (appSpecialSubVo.getNavType() == AppCommon.NAV_TYPE_TWO){
                    if (StringUtils.isEmpty(appSpecialSubVo.getH5TempAndroidUrl()) || StringUtils.isEmpty(appSpecialSubVo.getH5TempIosUrl())){
                        return Response.fail(BusinessMessage.NATYPE_H5_ERROR);
                    }
                }
            }
        }
         appGroupConfigService.addSpecial(appSpecialVo);
        return  Response.success();
    }
    /**
     * Title: 功能专题-修改
     * Description:
     * @param appSpecialVo
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 3:47 下午
     */
    @ApiOperation(value = "功能专题-修改",notes = "功能专题-修改")
    @ApiImplicitParam(name = "appSpecialVo",value = "请求入参封装",required =true,dataType = "AppSpecialVo")
    @PostMapping("special/update")
    public Response updateSpecial(@Valid @RequestBody AppSpecialVo appSpecialVo){
        log.info("AppBackstageController -> updateSpecial【功能专题-新增】入参【{}】", JSONUtil.toJsonStr(appSpecialVo));

        if (!CollectionUtils.isEmpty(appSpecialVo.getSpecialSubVoList())){
            for (AppSpecialSubVo appSpecialSubVo : appSpecialVo.getSpecialSubVoList()) {
                if (appSpecialSubVo.getNavType() == 1){
                    if (StringUtils.isEmpty(appSpecialSubVo.getAppId())){
                        return Response.fail(BusinessMessage.NATYPE_ERROR);
                    }
                }
                if (appSpecialSubVo.getNavType() == AppCommon.NAV_TYPE_TWO){
                    if (StringUtils.isEmpty(appSpecialSubVo.getH5TempAndroidUrl()) || StringUtils.isEmpty(appSpecialSubVo.getH5TempIosUrl())){
                        return Response.fail(BusinessMessage.NATYPE_H5_ERROR);
                    }
                }
            }
        }
        appGroupConfigService.updateSpecial(appSpecialVo);
        return  Response.success();
    }
    /**
     * Title: 功能专题-删除
     * Description:
     * @param map
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 3:47 下午
     */
    @ApiOperation(value = "功能专题-删除传入示例:{\"id\":12345}",notes = "功能专题-删除")
    @ApiImplicitParam(name = "map",value = "请求入参封装",required =true,dataType = "Map")
    @PostMapping("special/delete")
    public Response deleteSpecial(@Valid @RequestBody Map<String ,Long> map){
        log.info("AppBackstageController -> deleteSpecial【功能专题-删除】入参【{}】", JSONUtil.toJsonStr(map));

        if (map == null || map.get("id") == null){
            return Response.fail(BusinessMessage.PARAMS_ERROR);
        }
        appGroupConfigService.deleteSpecial(map.get("id"));
        return  Response.success();
    }
    //====================== 功能专题页 end =====================//

    //====================== 信豆引导页 start =====================//
    /**
     * Title: 信豆页-新增
     * Description:
     * @param letterBeanAppVo
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/28 8:44 上午
     */
    @ApiOperation(value = "信豆页-新增",notes = "信豆页-新增")
    @ApiImplicitParam(name = "letterBeanAppVo",value = "请求入参封装",required =true,dataType = "LetterBeanAppVo")
    @PostMapping("letterBean/add")
    public Response addLetterBeanApp(@Valid @RequestBody LetterBeanAppVo letterBeanAppVo){
        log.info("AppBackstageController -> addLetterBeanApp【 信豆页-新增】入参【{}】", JSONUtil.toJsonStr(letterBeanAppVo));
        if (letterBeanAppVo.getNavType() == 1){
            if (StringUtils.isEmpty(letterBeanAppVo.getAppId())){
                return Response.fail(BusinessMessage.NATYPE_ERROR);
            }
        }
        if (letterBeanAppVo.getNavType() == AppCommon.NAV_TYPE_TWO){
            if (StringUtils.isEmpty(letterBeanAppVo.getH5TempAndroidUrl()) || StringUtils.isEmpty(letterBeanAppVo.getH5TempIosUrl())){
                return Response.fail(BusinessMessage.NATYPE_H5_ERROR);
            }
        }
        AppConfig appConfig = new AppConfig();
        BeanUtils.copyProperties(letterBeanAppVo, appConfig);
        appConfig.setPlateType(AppCommon.APP_PLATE_TYPE_FOUR);
        appConfig.setDelFlag(AppCommon.APP_DEL_FLAG_ONE);
        appConfig.setDefaultIndex(AppCommon.APP_DEFAULT_ZERO);
        appConfig.setIsTitle(AppCommon.APP_IS_TITLE_ZERO);
        appConfig.setLogin(AppCommon.APP_LOGIN_ONE);
        appConfig.setAuthorize(AppCommon.APP_AUTHORIZE_ZERO);
        appConfig.setEditFlag(1);
        Response response =  checkVersionValue(appConfig.getStartVersionValue(),appConfig.getEndVersionValue());
        if (response != null){
            return response;
        }
        List<AppVersion> versionList = queryVersionNum(appConfig.getStartVersionValue(),appConfig.getEndVersionValue());
        if (CollectionUtils.isEmpty(versionList)){
            return Response.fail(BusinessMessage.VERSION_VALUE_ERROR);
        }
        for (AppVersion appVersion : versionList) {
            if (appVersion.getVersionValue().intValue() == appConfig.getStartVersionValue().intValue()){
                appConfig.setStartVersion(appVersion.getVersionNum());
            }
            if (appVersion.getVersionValue().intValue() == appConfig.getEndVersionValue().intValue()){
                appConfig.setEndVersion(appVersion.getVersionNum());
            }
        }
        List<AppConfig> list = new ArrayList<>();
        list.add(appConfig);
        appConfigService.insertAppConfigByList(list);
        return  Response.success();
    }

    private Response checkVersionValue(int startVersionValue, int endVersionValue) {
        if (startVersionValue> endVersionValue){
            return Response.fail("开始版本不能大于结束版本");
        }
        return null;
    }

    /**
     * Title: 信豆页-修改
     * Description:
     * @param letterBeanAppVo
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/28 8:45 上午
     */
    @ApiOperation(value = "信豆页-修改",notes = "信豆页-修改")
    @ApiImplicitParam(name = "letterBeanAppVo",value = "请求入参封装",required =true,dataType = "LetterBeanAppVo")
    @PostMapping("letterBean/update")
    public Response updateLetterBeanApp(@Valid @RequestBody LetterBeanAppVo letterBeanAppVo){
        log.info("AppBackstageController -> updateLetterBeanApp【 信豆页-修改】入参【{}】", JSONUtil.toJsonStr(letterBeanAppVo));

        if (letterBeanAppVo.getNavType() == 1){
            if (StringUtils.isEmpty(letterBeanAppVo.getAppId())){
                return Response.fail(BusinessMessage.NATYPE_ERROR);
            }
        }
        if (letterBeanAppVo.getNavType() == AppCommon.NAV_TYPE_TWO){
            if (StringUtils.isEmpty(letterBeanAppVo.getH5TempAndroidUrl()) || StringUtils.isEmpty(letterBeanAppVo.getH5TempIosUrl())){
                return Response.fail(BusinessMessage.NATYPE_H5_ERROR);
            }
        }
        AppConfig appConfig = new AppConfig();
        BeanUtils.copyProperties(letterBeanAppVo, appConfig);

        Response response =  checkVersionValue(appConfig.getStartVersionValue(),appConfig.getEndVersionValue());
        if (response != null){
            return response;
        }
        List<AppVersion> versionList = queryVersionNum(appConfig.getStartVersionValue(),appConfig.getEndVersionValue());
        if (CollectionUtils.isEmpty(versionList)){
            return Response.fail(BusinessMessage.VERSION_VALUE_ERROR);
        }
        for (AppVersion appVersion : versionList) {
            if (appVersion.getVersionValue().intValue() == appConfig.getStartVersionValue().intValue()){
                appConfig.setStartVersion(appVersion.getVersionNum());
            }
            if (appVersion.getVersionValue().intValue() == appConfig.getEndVersionValue().intValue()){
                appConfig.setEndVersion(appVersion.getVersionNum());
            }
        }
        List<AppConfig> list = new ArrayList<>();
        list.add(appConfig);
        appConfigService.updateAppConfigByList(list);
        return  Response.success();
    }
    @ApiOperation(value = "信豆页-根据ID删除",notes = "信豆页-根据ID删除")
    @ApiImplicitParam(name = "map",value = "ID：示例 \"id:\"123",required =true,dataType = "Map")
    @PostMapping("letterBean/delete")
    public Response deleteLetterBeanApp(@Valid @RequestBody Map<String,Long> map){
        log.info("AppBackstageController -> deleteLetterBeanApp【信豆页-根据ID删除】入参【{}】", JSONUtil.toJsonStr(map));

        if (map == null || map.get("id") == null){
            return Response.fail(BusinessMessage.PARAMS_ERROR);
        }
        appConfigService.deleteAppConfig(map.get("id"));
        return Response.success();
    }
    /**
     * Title: 信豆页-查询
     * Description:
     * @param pageVo
     * @return: conson.tech.core.response.Response<com.baomidou.mybatisplus.extension.plugins.pagination.Page<conson.tech.manage.app.entity.vo.LetterBeanAppVo>>
     * Company: GX
     * Author HXL
     * Date 2020/4/28 8:52 上午
     */
    @ApiOperation(value = "信豆页-查询",notes = "信豆页-查询")
    @ApiImplicitParam(name = "pageVo",value = "请求入参封装",required =true,dataType = "PageVo")
    @PostMapping("letterBean/query")
    public Response<Page<LetterBeanAppVo>> queryLetterBean(@Valid @RequestBody PageVo pageVo){
        Page<LetterBeanAppVo> page = appConfigService.queryLetterBeanApp(pageVo);
        return  Response.success(page);
    }

    //====================== 信豆引导页 end =====================//

    //====================== 版本 start =====================//
    /**
     * Title: 版本控制--新增
     * Description:
     * @param vo
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 11:36 上午
     */
    @ApiOperation(value = "版本控制--新增",notes = "版本控制--新增")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "AppVersionVo")
    @PostMapping("version/add")
    public Response addVersion(@Valid @RequestBody AppVersionVo vo){
        log.info("AppBackstageController -> addVersion【版本控制--新增】入参【{}】", JSONUtil.toJsonStr(vo));
       List<AppVersion> list =  appVersionService.checkAppVersion(vo);
        if (!CollectionUtils.isEmpty(list)){
           return Response.fail(BusinessMessage.VERSION_NUM_VALUE_ERROR);
       }
        if (vo.getVersionState() == AppCommon.VERSION_STATE_ONE) {
            List<AppVersion> versionList = appVersionService.queryNewVersionData(vo.getVersionState(), vo.getPlatformType());
            if (!CollectionUtils.isEmpty(versionList)) {
                return Response.fail(BusinessMessage.VERSION_NEW_VALUE_ERROR);
            }
        }
        appVersionService.addVersion(vo);
        return Response.success();
    }
    /**
     * Title: 版本控制-根据ID修改版本
     * Description:
     * @param vo
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 11:36 上午
     */
    @ApiOperation(value = "版本控制-根据ID修改版本",notes = "版本控制-根据ID修改版本")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "AppVersionVo")
    @PostMapping("version/update")
    public Response updateVersion(@Valid @RequestBody AppVersionVo vo){
        log.info("AppBackstageController -> addVersion【版本控制-根据ID修改版本】入参【{}】", JSONUtil.toJsonStr(vo));

        List<AppVersion> list =  appVersionService.checkAppVersion(vo);
        if (!CollectionUtils.isEmpty(list)){
            if (list.get(0).getId() != vo.getId()) {
                return Response.fail(BusinessMessage.VERSION_NUM_VALUE_ERROR);
            }
        }
        if (vo.getVersionState() == AppCommon.VERSION_STATE_ONE) {
            List<AppVersion> versionList = appVersionService.queryNewVersionData(vo.getVersionState(), vo.getPlatformType());
            if (!CollectionUtils.isEmpty(versionList)) {
                if (versionList.get(0).getId() != vo.getId()) {
                    return Response.fail(BusinessMessage.VERSION_NEW_VALUE_ERROR);
                }
            }
        }
        appVersionService.updateVersion(vo);
        return Response.success();
    }
    /**
     * Title: 版本控制-查询10个最近创建的版本
     * Description:
     * @param
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 11:12 上午
     */
    @ApiOperation(value = "版本控制-查询10个最近创建的版本",notes = "版本控制-查询10个最近创建的版本")
    //@ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "AppVersionVo")
    @GetMapping("version/queryList")
    public Response queryAppVersionList(){
        List<QueryAppVersionVo> list = appVersionService.queryAppVersionList();
        QueryAppVersionVo versionVo = new QueryAppVersionVo();
        for (QueryAppVersionVo vo : list) {
            vo.setVersionName(vo.getVersionNum());
        }
        versionVo.setVersionNum(AppCommon.VERSION_NAME);
        versionVo.setVersionName(AppCommon.VERSION_NAME);
        versionVo.setVersionValue(AppCommon.VERSION_VALUE);
        list.add(0,versionVo);
        return Response.success(list);
    }
    @ApiOperation(value = "版本控制-分页查询app版本",notes = "版本控制-分页查询app版本")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "PageVo")
    @PostMapping("version/queryPage")
    public Response<Page<AppVersionVo>> queryAppVersionPage(@Valid @RequestBody PageVo vo){
        Page<AppVersionVo> page = appVersionService.queryAppVersionPage(vo);
        return Response.success(page);
    }
    //====================== 版本 end =====================//

    //====================== 首页生活页 start =====================//
    /**
     * Title: 查询分类/分组
     * Description:
     * @param
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 10:22 上午
     */
    @ApiOperation(value = "查询分类/分组:0首页1生活页2.应用3功能专题4信豆页.示例:{\"requestPageType\":1}",notes = "查询分类/分组")
    @ApiImplicitParam(name = "map",value = "示例:{\"requestPageType\":1}",required =true,dataType = "Map")
    @PostMapping("group/queryGroupList")
    public Response<List<QueryAppGroupVo> > queryGroupList(@Valid @RequestBody Map<String , Integer> map){
        if (map == null || map.get("requestPageType") == null){
            return Response.fail(BusinessMessage.PARAMS_ERROR);
        }
        List<QueryAppGroupVo> groupList = appGroupConfigService.queryGroupList(map.get("requestPageType"));

        return Response.success(groupList);
    }

    /**
     * Title: 首页生活页-根据模块ID删除模块以及该模块下面的所有分组和app
     * Description:
     * @param map
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 10:13 上午
     */
    @ApiOperation(value = "首页生活页-根据模块ID删除模块以及该模块下面的所有分组和app.示例:{\"moduleId\":122}",notes = "首页生活页-根据模块ID删除模块以及该模块下面的所有分组和app")
    @ApiImplicitParam(name = "map",value = "示例:{\"moduleId\":122}",required =true,dataType = "Map")
    @PostMapping("page/delete")
    public Response deleteAllConfig(@Valid @RequestBody Map<String,Long> map){
        log.info("AppBackstageController -> deleteAllConfig【首页生活页-根据模块ID删除模块以及该模块下面的所有分组和app】入参【{}】", JSONUtil.toJsonStr(map));

        if (map == null || map.get("moduleId") == null){
            return Response.fail(BusinessMessage.PARAMS_ERROR);
        }
       int result = appPageConfigService.deleteAppPageConfig(map.get("moduleId"));
        return Response.success();
    }
    /**
     * Title: 首页生活页-配置模块新增
     * Description:
     * @param vo
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/26 11:50 上午
     */
    @ApiOperation(value = "首页生活页-配置模块新增",notes = "首页生活页-配置模块新增")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "AllConfigVo")
    @PostMapping("page/add")
    public Response addAllConfig(@Valid @RequestBody AllConfigVo vo){
        log.info("AppBackstageController -> addAllConfig【首页生活页-配置模块新增】入参【{}】", JSONUtil.toJsonStr(vo));
        Response response = checkParam(vo,"add");
        if (response != null){
            return response;
        }

        Response response1 =  checkVersionValue(vo.getStartVersionValue(),vo.getEndVersionValue());
        if (response1 != null){
            return response1;
        }
        List<AppVersion> versionList = queryVersionNum(vo.getStartVersionValue(),vo.getEndVersionValue());
        if (CollectionUtils.isEmpty(versionList)){
            return Response.fail(BusinessMessage.VERSION_VALUE_ERROR);
        }
        for (AppVersion appVersion : versionList) {
            if (appVersion.getVersionValue().intValue() == vo.getStartVersionValue().intValue()){
                vo.setStartVersion(appVersion.getVersionNum());
            }
            if (appVersion.getVersionValue().intValue() == vo.getEndVersionValue().intValue()){
                vo.setEndVersion(appVersion.getVersionNum());
            }
        }
        AppPageConfig pageConfig =  setAppPageConfigData(vo);
        Long pageId = appPageConfigService.insertAppPageConfig(pageConfig);
        //appPageConfigService
        if (!CollectionUtils.isEmpty(vo.getTwoConfigVoList())){
            List<AppGroupConfig> groupConfigList = setAppGroupConfigData(vo, pageId);
            appGroupConfigService.appAddGroupByList(groupConfigList);
        }
        if (!CollectionUtils.isEmpty(vo.getThreeConfigVoList())){

            List<AppConfig> appConfigList = setAppConfigData(vo);
            appConfigService.insertAppConfigByList(appConfigList);
        }
        return Response.success();
    }

    private List<AppVersion> queryVersionNum(int startVersionValue, int endVersionValue) {
        List<Integer> list = new ArrayList<>();

        if (startVersionValue != AppCommon.VERSION_VALUE && endVersionValue != AppCommon.VERSION_VALUE) {
            if (startVersionValue == endVersionValue){
                list.add(startVersionValue);
            }else {
                list.add(startVersionValue);
                list.add(endVersionValue);
            }
            return appVersionService.queryAppVersionByValue(list);
        }else if(startVersionValue == AppCommon.VERSION_VALUE && endVersionValue != AppCommon.VERSION_VALUE ){
            list.add(endVersionValue);
            List<AppVersion> versionList = appVersionService.queryAppVersionByValue(list);
            AppVersion appVersion = new AppVersion();
            appVersion.setVersionNum(AppCommon.VERSION_NAME);
            appVersion.setVersionValue(AppCommon.VERSION_VALUE);
            versionList.add(appVersion);
            return  versionList;
        }else if (startVersionValue != AppCommon.VERSION_VALUE && endVersionValue == AppCommon.VERSION_VALUE){
            list.add(startVersionValue);
            List<AppVersion> versionList = appVersionService.queryAppVersionByValue(list);
            AppVersion appVersion = new AppVersion();
            appVersion.setVersionNum(AppCommon.VERSION_NAME);
            appVersion.setVersionValue(AppCommon.VERSION_VALUE);
            versionList.add(appVersion);
            return  versionList;
        }else if (startVersionValue == AppCommon.VERSION_VALUE && endVersionValue == AppCommon.VERSION_VALUE){
            List<AppVersion> versionList = new ArrayList<>();
            AppVersion appVersion = new AppVersion();
            appVersion.setVersionNum(AppCommon.VERSION_NAME);
            appVersion.setVersionValue(AppCommon.VERSION_VALUE);
            versionList.add(appVersion);
            return versionList;
        }
        return null;
    }

    /**
     * Title: 首页生活页-修改
     * Description:
     * @param vo
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 9:30 上午
     */
    @ApiOperation(value = "首页生活页修改",notes = "首页生活页修改")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "AllConfigVo")
    @PostMapping("page/update")
    public Response updateAllConfig(@Valid @RequestBody AllConfigVo vo){
        log.info("AppBackstageController -> updateAllConfig【首页生活页修改】入参【{}】", JSONUtil.toJsonStr(vo));

        Response response = checkParam(vo,"update");
        if (response != null){
            return response;
        }
        Response response1 =  checkVersionValue(vo.getStartVersionValue(),vo.getEndVersionValue());
        if (response1 != null){
            return response1;
        }
        List<AppVersion> versionList = queryVersionNum(vo.getStartVersionValue(),vo.getEndVersionValue());
        if (CollectionUtils.isEmpty(versionList)){
            return Response.fail(BusinessMessage.VERSION_VALUE_ERROR);
        }
        for (AppVersion appVersion : versionList) {
            if (appVersion.getVersionValue().intValue() == vo.getStartVersionValue().intValue()){
                vo.setStartVersion(appVersion.getVersionNum());
            }
            if (appVersion.getVersionValue().intValue() == vo.getEndVersionValue().intValue()){
                vo.setEndVersion(appVersion.getVersionNum());
            }
        }
        AppPageConfig pageConfig =  setAppPageConfigData(vo);
         appPageConfigService.updateAppPageConfig(pageConfig);
        if (!CollectionUtils.isEmpty(vo.getTwoConfigVoList())){
            List<AppGroupConfig> groupConfigList = setAppGroupConfigData(vo,pageConfig.getId());
            List<AppGroupConfig> updateGroupConfigList = new ArrayList<>();
            List<AppGroupConfig> newGroupConfigList = new ArrayList<>();
            for (AppGroupConfig appGroupConfig : groupConfigList) {
                if (appGroupConfig.getId() != null){
                    updateGroupConfigList.add(appGroupConfig);
                }else {
                    newGroupConfigList.add(appGroupConfig);
                }
            }
            if (!CollectionUtils.isEmpty(updateGroupConfigList)) {
                appGroupConfigService.appUpdateGroupByList(updateGroupConfigList);
            }
            if (!CollectionUtils.isEmpty(newGroupConfigList)){
                appGroupConfigService.appAddGroupByList(newGroupConfigList);
            }
        }
        if (!CollectionUtils.isEmpty(vo.getThreeConfigVoList())){
            List<AppConfig> configList =  setAppConfigData(vo);
            List<AppConfig> updateConfigList = new ArrayList<>();
            List<AppConfig> newConfigList = new ArrayList<>();
            for (AppConfig appConfig : configList) {
                if (appConfig.getId() != null){
                    updateConfigList.add(appConfig);
                }else {
                    newConfigList.add(appConfig);
                }
            }
            if (!CollectionUtils.isEmpty(updateConfigList)){
                appConfigService.updateAppConfigByList(updateConfigList);
            }
            if (!CollectionUtils.isEmpty(newConfigList)){
                appConfigService.insertAppConfigByList(newConfigList);
            }

        }
        return Response.success();
    }
    /**
     * Title: 首页生活页-分页查询
     * Description:
     * @param vo
     * @return: conson.tech.core.response.Response<com.baomidou.mybatisplus.extension.plugins.pagination.Page<conson.tech.manage.app.entity.vo.AppPageConfigVo>>
     * Company: GX
     * Author HXL
     * Date 2020/4/27 9:24 上午
     */
    @ApiOperation(value = "首页生活页-分页查询",notes = "首页生活页-分页查询")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "PageVo")
    @PostMapping("page/queryPageList")
    public Response<Page<AppPageConfigVo>> queryPageList(@Valid @RequestBody PageVo vo){
        if (vo == null || vo.getPageRequestType() == null){
            return Response.fail(BusinessMessage.PARAMS_ERROR);
        }
        Page<AppPageConfigVo> page = appPageConfigService.queryPageList(vo);
        return Response.success(page);
    }
    //====================== 首页生活页 end =====================//

    //====================== 应用配置 start =====================//
    /**
     * Title: 应用配置-新增应用
     * Description:
     * @param vo
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 2:19 下午
     */
    @ApiOperation(value = "应用配置-新增应用",notes = "应用配置-新增应用")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "AppConfigAllVo")
    @PostMapping("app/addApp")
    public Response addAppConfig(@Valid @RequestBody AppConfigAllVo vo){
        log.info("AppBackstageController -> addAppConfig【应用配置-新增应用】入参【{}】", JSONUtil.toJsonStr(vo));

        Response response1 =  checkVersionValue(vo.getStartVersionValue(),vo.getEndVersionValue());
        if (response1 != null){
            return response1;
        }
        if (vo.getNavType() == AppCommon.NAV_TYPE_ONE){
            if (StringUtils.isEmpty(vo.getAppId())){
                return Response.fail(BusinessMessage.NATYPE_ERROR);
            }
        }
        if (vo.getNavType() == AppCommon.NAV_TYPE_TWO){
            if (StringUtils.isEmpty(vo.getH5TempAndroidUrl()) || StringUtils.isEmpty(vo.getH5TempIosUrl())){
                return Response.fail(BusinessMessage.NATYPE_H5_ERROR);
            }
        }
        AppConfig appConfig = new AppConfig();
        BeanUtils.copyProperties(vo, appConfig);
        appConfig.setPlateType(AppCommon.APP_PLATE_TYPE_TWO);
        appConfig.setDelFlag(AppCommon.APP_DEL_FLAG_ONE);
        appConfig.setDefaultIndex(AppCommon.APP_DEFAULT_ZERO);
        appConfig.setIsTitle(AppCommon.APP_IS_TITLE_ZERO);
        appConfig.setLogin(AppCommon.APP_LOGIN_ONE);
        appConfig.setAuthorize(AppCommon.APP_AUTHORIZE_ZERO);
        appConfig.setEditFlag(1);
        List<AppVersion> versionList = queryVersionNum(appConfig.getStartVersionValue(),appConfig.getEndVersionValue());
        if (CollectionUtils.isEmpty(versionList)){
            return Response.fail(BusinessMessage.VERSION_VALUE_ERROR);
        }
        for (AppVersion appVersion : versionList) {
            if (appVersion.getVersionValue().intValue() == appConfig.getStartVersionValue().intValue()){
                appConfig.setStartVersion(appVersion.getVersionNum());
            }
            if (appVersion.getVersionValue().intValue() == appConfig.getEndVersionValue().intValue()){
                appConfig.setEndVersion(appVersion.getVersionNum());
            }
        }
        List<AppConfig> list = new ArrayList<>();
        list.add(appConfig);
        appConfigService.insertAppConfigByList(list);
        return Response.success();
    }
    /**
     * Title: 应用配置-修改应用
     * Description:
     * @param vo
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 2:20 下午
     */
    @ApiOperation(value = "应用配置-修改应用",notes = "应用配置-修改应用")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "AppConfigAllVo")
    @PostMapping("app/updateApp")
    public Response updateAppConfig(@Valid @RequestBody AppConfigAllVo vo){
        log.info("AppBackstageController -> updateAppConfig【应用配置-修改应用】入参【{}】", JSONUtil.toJsonStr(vo));

        Response response1 =  checkVersionValue(vo.getStartVersionValue(),vo.getEndVersionValue());
        if (response1 != null){
            return response1;
        }
        if (vo.getNavType() == AppCommon.NAV_TYPE_ONE){
            if (StringUtils.isEmpty(vo.getAppId())){
                return Response.fail(BusinessMessage.NATYPE_ERROR);
            }
        }
        if (vo.getNavType() == AppCommon.NAV_TYPE_TWO){
            if (StringUtils.isEmpty(vo.getH5TempAndroidUrl()) || StringUtils.isEmpty(vo.getH5TempIosUrl())){
                return Response.fail(BusinessMessage.NATYPE_H5_ERROR);
            }
        }
        AppConfig appConfig = new AppConfig();
        BeanUtils.copyProperties(vo, appConfig);
        List<AppVersion> versionList = queryVersionNum(appConfig.getStartVersionValue(),appConfig.getEndVersionValue());
        if (CollectionUtils.isEmpty(versionList)){
            return Response.fail(BusinessMessage.VERSION_VALUE_ERROR);
        }
        for (AppVersion appVersion : versionList) {
            if (appVersion.getVersionValue().intValue() == appConfig.getStartVersionValue().intValue()){
                appConfig.setStartVersion(appVersion.getVersionNum());
            }
            if (appVersion.getVersionValue().intValue() == appConfig.getEndVersionValue().intValue()){
                appConfig.setEndVersion(appVersion.getVersionNum());
            }
        }
        List<AppConfig> list = new ArrayList<>();
        list.add(appConfig);
        appConfigService.updateAppConfigByList(list);
        return Response.success();
    }
    /**
     * Title: 应用配置-删除应用
     * Description:
     * @param map
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 2:20 下午
     */
    @ApiOperation(value = "应用配置-删除应用.示例:{\"id\":1234}",notes = "应用配置-删除应用")
    @ApiImplicitParam(name = "map",value = "示例:{\"id\":1234}",required =true,dataType = "Map")
    @PostMapping("app/deleteApp")
    public Response deleteAppConfig(@Valid @RequestBody Map<String,Long> map){
        log.info("AppBackstageController -> deleteAppConfig【应用配置-删除应用】入参【{}】", JSONUtil.toJsonStr(map));

        if (map == null || map.get("id") == null){
            return Response.fail(BusinessMessage.PARAMS_ERROR);
        }
        appConfigService.deleteAppConfig(map.get("id"));
        return Response.success();
    }
    /**
     * Title: 应用配置-分页查询
     * Description:
     * @param vo
     * @return: conson.tech.core.response.Response<com.baomidou.mybatisplus.extension.plugins.pagination.Page<conson.tech.manage.app.entity.vo.AppConfigVo>>
     * Company: GX
     * Author HXL
     * Date 2020/4/27 9:30 上午
     */
    @ApiOperation(value = "应用配置-分页查询",notes = "应用配置-分页查询")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "PageVo")
    @PostMapping("app/queryAppPage")
    public Response<Page<AppConfigAllVo>> queryAppConfigPage(@Valid @RequestBody PageVo vo){
        if (vo == null || vo.getPageRequestType() == null){
            return Response.fail("参数不完整");
        }
        Page<AppConfigAllVo> page = appConfigService.queryAppConfigPage(vo);
        return Response.success(page);
    }



    @ApiOperation(value = "默认应用-分页查询",notes = "默认应用-分页查询")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "PageVo")
    @PostMapping("app/queryDefault")
    public Response<Page<DefaultAppVo>> queryDefaultApp(@Valid @RequestBody PageVo vo){
       Page<DefaultAppVo> page = appConfigService.queryDefaultApp(vo);
        return Response.success(page);
    }
    /**
     * Title: 默认应用-选择应用
     * Description:
     * @param
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/28 9:20 上午
     */
    @ApiOperation(value = "默认应用-选择应用",notes = "默认应用-选择应用")
    @GetMapping("app/selectApp")
    public Response<List<SelectAppVo>> querySelectApp(){
       List<SelectAppVo> list= appConfigService.querySelectApp();
        return Response.success(list);
    }
    /**
     * Title: 默认应用-添加/删除/修改
     * Description:
     * @param vo
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/28 9:20 上午
     */
    @ApiOperation(value = "默认应用-添加/删除/修改",notes = "默认应用-添加/删除/修改")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "DefaultAppRequestVo")
    @PostMapping("app/setDefault")
    public Response setDefaultApp(@Valid @RequestBody DefaultAppRequestVo vo){
        log.info("AppBackstageController -> setDefaultApp【默认应用-添加/删除/修改】入参【{}】", JSONUtil.toJsonStr(vo));
        if (vo == null || vo.getId() == null){
            return Response.fail(BusinessMessage.PARAMS_ERROR);
        }
        appConfigService.setDefaultApp(vo);
        return Response.success();
    }
    /**
     * Title: 应用配置-分页查询分组列表
     * Description:
     * @param vo
     * @return: conson.tech.core.response.Response<com.baomidou.mybatisplus.extension.plugins.pagination.Page<conson.tech.manage.app.entity.vo.AppGroupConfigVo>>
     * Company: GX
     * Author HXL
     * Date 2020/4/24 2:29 下午
     */
    @ApiOperation(value = "应用配置-分页查询分组列表",notes = "应用配置-分页查询分组列表")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "PageVo")
    @PostMapping("app/queryGroupList")
    public Response<Page<AppClassVo>> queryGroupList(@Valid @RequestBody PageVo vo){
        if (vo == null){
            return Response.fail(BusinessMessage.PARAMS_ERROR);
        }
        Page<AppClassVo> page = appGroupConfigService.queryGroupListPage(vo);
        return Response.success(page);
    }
    /**
     * Title: 应用配置-新增分组
     * Description:
     * @param vo
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 10:19 上午
     */
    @ApiOperation(value = "应用配置-新增分组",notes = "应用配置-新增分组")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "AppClassVo")
    @PostMapping("app/addGroup")
    public Response appAddGroup(@Valid @RequestBody AppClassVo vo){
        log.info("AppBackstageController -> appAddGroup【应用配置-新增分组】入参【{}】", JSONUtil.toJsonStr(vo));

        if (vo == null || StringUtils.isEmpty(vo.getName()) || vo.getSort() == null){
            return Response.fail(BusinessMessage.PARAMS_ERROR);
        }
        AppGroupConfig groupConfig = new AppGroupConfig();
        groupConfig.setDelFlag(AppCommon.APP_DEL_FLAG_ONE);
        groupConfig.setGroupType(AppCommon.GROUP_TYPE_TWO);
        groupConfig.setSort(vo.getSort());
        groupConfig.setName(vo.getName());
        groupConfig.setOpen(AppCommon.APP_OPEN_ONE);
        appGroupConfigService.appAddGroup(groupConfig);
        return Response.success();
    }
    /**
     * Title: 应用配置-根据ID修改分组
     * Description:
     * @param vo
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 9:26 上午
     */
    @ApiOperation(value = "应用配置-根据ID修改分组",notes = "应用配置-根据ID修改分组")
    @ApiImplicitParam(name = "vo",value = "请求入参封装",required =true,dataType = "AppClassVo")
    @PostMapping("app/updateGroup")
    public Response appUpdateGroup(@Valid @RequestBody AppClassVo vo){
        log.info("AppBackstageController -> appUpdateGroup【应用配置-根据ID修改分组】入参【{}】", JSONUtil.toJsonStr(vo));

        if (vo == null || vo.getId() == null||StringUtils.isEmpty(vo.getName()) || vo.getSort() == null){
            return Response.fail(BusinessMessage.PARAMS_ERROR);
        }
        AppGroupConfig groupConfig = new AppGroupConfig();
        groupConfig.setSort(vo.getSort());
        groupConfig.setName(vo.getName());
        groupConfig.setId(vo.getId());
        appGroupConfigService.appUpdateGroup(groupConfig);
        return Response.success();
    }
    /**
     * Title: 应用配置-根据ID删除分组
     * Description:
     * @param map
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 9:28 上午
     */
    @ApiOperation(value = "应用配置-根据ID删除分组",notes = "应用配置-根据ID删除分组")
    @ApiImplicitParam(name = "map",value = "示例:{\"id\":1234}",required =true,dataType = "Map")
    @PostMapping("app/deleteGroup")
    public Response appDeleteGroup( @RequestBody Map<String,Long> map){
        log.info("AppBackstageController -> appDeleteGroup【应用配置-根据ID删除分组】入参【{}】", JSONUtil.toJsonStr(map));

        if (map == null || map.get("id") == null){
            return Response.fail(BusinessMessage.PARAMS_ERROR);
        }
        AppGroupConfig groupConfig = new AppGroupConfig();
         groupConfig.setDelFlag(0);
        groupConfig.setId(map.get("id"));
        appGroupConfigService.appDeleteGroup(groupConfig);
        return Response.success();
    }

    /**
     * Title: 查询ID页
     * Description:
     * @return: conson.tech.core.response.Response
     * Company: GX
     * Author HXL
     * Date 2020/4/27 9:28 上午
     */
    @ApiOperation(value = "查询ID页",notes = "查询ID页")
    @PostMapping("app/idGroup")
    public Response appIdGroup(){
        return Response.success(appConfigService.getAllAppMaintainConfig());
    }


    //====================== 应用配置 end =====================//

    //校验首页生活页参数
    private Response checkParam(AllConfigVo vo, String methodType) {
        if (vo == null ){
            return Response.fail("实体参数不能为空");
        }
        if ("update".equals(methodType)){
            if (vo.getModuleId() == null){
                return Response.fail("模块ID不能为空");
            }
        }
        if (StringUtils.isEmpty(vo.getModuleName())){
            return Response.fail("模块名称不能为空");
        }
        if (vo.getModuleSort() == null){
            return Response.fail("模块排序不能为空");
        }
        if (vo.getContentType() == null){
            return Response.fail("模块样式不能为空");
        }
        if (vo.getOpen() == null){
            return Response.fail("启用状态不能为空");
        }
      /*  if (StringUtils.isEmpty(vo.getStartVersion()) || StringUtils.isEmpty(vo.getEndVersion())){
            return Response.fail("生效版本不能为空");
        }*/
        if (StringUtils.isEmpty(vo.getOneTitleName())){
            return Response.fail("第一层标题不能为空");
        }
        if (vo.getIconFlag() == null){
            return Response.fail("第一层显示标签不能为空");
        }
        if (!CollectionUtils.isEmpty(vo.getTwoConfigVoList())){
            for (AppTwoConfigVo appTwoConfigVo : vo.getTwoConfigVoList()) {
                if (appTwoConfigVo == null)continue;
                if ("update".equals(methodType)){
                    if (appTwoConfigVo.getTowGroupId() == null){
                        return Response.fail("第二层id不能为空");
                    }
                }
                if (StringUtils.isEmpty(appTwoConfigVo.getTwoTitleName())){
                    return Response.fail("第二层标题不能为空");
                }
                if (StringUtils.isEmpty(appTwoConfigVo.getTwoPictureUrl())){
                    return Response.fail("第二层图片地址不能为空");
                }
                if (appTwoConfigVo.getTwoSort() == null){
                    return Response.fail("第二层排序地址不能为空");
                }
            }
        }
        if (!CollectionUtils.isEmpty(vo.getThreeConfigVoList())){
            for (AppThreeConfigVo appThreeConfigVo : vo.getThreeConfigVoList()) {
                if (appThreeConfigVo == null)continue;
                if ("update".equals(methodType)){
                    if (appThreeConfigVo.getThreeId() == null){
                        return Response.fail("第三层id不能为空");
                    }
                }
                if (StringUtils.isEmpty(appThreeConfigVo.getThreeTitleName())){
                    return Response.fail("第三层标题不能为空");
                }
                if (StringUtils.isEmpty(appThreeConfigVo.getThreePictureUrl())){
                    return Response.fail("第三层图片地址不能为空");
                }
                if (appThreeConfigVo.getTreeSort() == null){
                    return Response.fail("第三层排序地址不能为空");
                }
                if (appThreeConfigVo.getThreeGroupId() == null){
                    return Response.fail("第三层选择第二层不能为空");
                }
                if (appThreeConfigVo.getThreeNavType() == null){
                    return Response.fail("第三层链接类型不能为空");
                }
                if (appThreeConfigVo.getThreeNavType() == 1){//ID页
                    if (StringUtils.isEmpty(appThreeConfigVo.getThreeAppId())){
                        return Response.fail("第三层链接类型是ID页时ID页的ID不能为空");
                    }
                }else {
                    if (StringUtils.isEmpty(appThreeConfigVo.getThreeAndroidUrl()) ||
                        StringUtils.isEmpty(appThreeConfigVo.getThreeIosUrl())){
                        return Response.fail("第三层链接类型是H5临时链接时android和iOS地址不能为空");
                    }
                }
            }
        }

        return null;
    }
    //设置app参数
    private List<AppConfig> setAppConfigData(AllConfigVo vo) {
        List<AppConfig> appConfigList = new ArrayList<>();
        List<AppThreeConfigVo> threeConfigVoList = vo.getThreeConfigVoList();
        for (AppThreeConfigVo threeConfigVo : threeConfigVoList) {
            AppConfig appConfig = new AppConfig();
            appConfig.setDelFlag(AppCommon.APP_DEL_FLAG_ONE);
            appConfig.setDefaultIndex(AppCommon.APP_DEFAULT_ZERO);
            appConfig.setCustomIconUrl(threeConfigVo.getThreePictureUrl());
            appConfig.setGroupId(threeConfigVo.getThreeGroupId());
            appConfig.setStartVersion(vo.getStartVersion());
            appConfig.setEndVersion(vo.getEndVersion());
            appConfig.setStartVersionValue(vo.getStartVersionValue());
            appConfig.setEndVersionValue(vo.getEndVersionValue());
            appConfig.setOpen(vo.getOpen());
            appConfig.setName(threeConfigVo.getThreeTitleName());
            appConfig.setNavType(threeConfigVo.getThreeNavType());
            appConfig.setSort(threeConfigVo.getTreeSort());
            appConfig.setH5TempAndroidUrl(threeConfigVo.getThreeAndroidUrl());
            appConfig.setH5TempIosUrl(threeConfigVo.getThreeIosUrl());
            appConfig.setAppId(threeConfigVo.getThreeAppId());
            appConfig.setPlateType(vo.getRequestPageType());
            appConfig.setId(threeConfigVo.getThreeId());
            appConfig.setEditFlag(1);
            appConfigList.add(appConfig);
        }
        return appConfigList;
    }
    //设置分组参数
    private List<AppGroupConfig> setAppGroupConfigData(AllConfigVo vo, Long pageId) {
        List<AppGroupConfig> groupConfigList = new ArrayList<>();
        List<AppTwoConfigVo> twoConfigVoList = vo.getTwoConfigVoList();
        for (AppTwoConfigVo twoConfigVo : twoConfigVoList) {
            AppGroupConfig groupConfig = new AppGroupConfig();
            groupConfig.setName(twoConfigVo.getTwoTitleName());
            groupConfig.setOpen(vo.getOpen());
            groupConfig.setSort(twoConfigVo.getTwoSort());
            groupConfig.setStartVersion(vo.getStartVersion());
            groupConfig.setEndVersion(vo.getEndVersion());
            groupConfig.setStartVersionValue(vo.getStartVersionValue());
            groupConfig.setEndVersionValue(vo.getEndVersionValue());
            groupConfig.setCustomIconUrl(twoConfigVo.getTwoPictureUrl());
            groupConfig.setDelFlag(AppCommon.APP_DEL_FLAG_ONE);
            groupConfig.setGroupType(vo.getRequestPageType());
            groupConfig.setAppPageConfigId(pageId);
            groupConfig.setId(twoConfigVo.getTowGroupId());
            groupConfigList.add(groupConfig);
        }

        return groupConfigList;
    }
    //设置页面（模块）参数
    private AppPageConfig setAppPageConfigData(AllConfigVo vo) {
        AppPageConfig pageConfig = new AppPageConfig();
        pageConfig.setDelFlag(AppCommon.APP_DEL_FLAG_ONE);
        pageConfig.setModuleName(vo.getModuleName());
        pageConfig.setSort(vo.getModuleSort());
        if(vo.getContentType() == 1){
            pageConfig.setContentType(3);
        }else if (vo.getContentType() == 2){
            pageConfig.setContentType(4);
        }else if (vo.getContentType() == 3){
            pageConfig.setContentType(5);
        }
       // pageConfig.setContentType(vo.getContentType());
        pageConfig.setOpen(vo.getOpen());
        pageConfig.setStartVersion(vo.getStartVersion());
        pageConfig.setEndVersion(vo.getEndVersion());
        pageConfig.setStartVersionValue(vo.getStartVersionValue());
        pageConfig.setEndVersionValue(vo.getEndVersionValue());
        pageConfig.setName(vo.getOneTitleName());
        pageConfig.setIconFlag(vo.getIconFlag());
        pageConfig.setPageType(vo.getRequestPageType());
        pageConfig.setId(vo.getModuleId());
        return pageConfig;
    }
}
